package kr.hkit.summart_java.serviceUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.sql.Connection;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import kr.hkit.myframework.db.ConnectionFactory;
import kr.hkit.summart_java.dao.CodeTitleDAO;
import kr.hkit.summart_java.dao.DepartmentDAO;
import kr.hkit.summart_java.dao.EmployeeDAO;
//import kr.hkit.summary_java.serviceUI.PanelDepartmentUI;

//import kr.hkit.summary_java.serviceUI.PanelDepartmentUI;

import java.awt.FlowLayout;

import javax.swing.BoxLayout;

import java.awt.GridLayout;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TestFrame extends JFrame implements ActionListener {
	private JMenuItem MItemdeptadd;
	private JMenuBar menuBar;
	private JMenu menusel;
	private JMenu mnNewMenu;
	private JMenu mnNewMenu2;
	private Connection con = ConnectionFactory.getConnection();
	private DepartmentDAO dao = new DepartmentDAO(con);
	private EmployeeDAO dao2 = new EmployeeDAO(con);
	private CodeTitleDAO dao3 = new CodeTitleDAO(con);
	private JMenuItem MItemdeptdel;
	private JMenuItem MItemdeptupd;
	private JMenuItem MItemdeptsear;
	private JMenuItem MItemdeptlist;
	private JMenuItem MItemempadd;
	private JMenuItem MItemempdel;
	private JMenuItem MItemempupd;
	private JMenuItem MItemempsear;
	private JMenuItem MItememplist;	
	private JMenuItem MItemcodeadd;
	private JMenuItem MItemcodedel;
	private JMenuItem MItemcodeupd;
	private JMenuItem MItemcodesear;
	private JMenuItem MItemcodelist;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestFrame frame = new TestFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TestFrame() {
		initialize();
	}

	private void initialize() {

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		menusel = new JMenu("Department");
		menuBar.add(menusel);
////////////////////////dapartment
		MItemdeptadd = new JMenuItem("추가");
		MItemdeptadd.addActionListener(this);
		menusel.add(MItemdeptadd);

		MItemdeptdel = new JMenuItem("삭제");
		MItemdeptdel.addActionListener(this);
		menusel.add(MItemdeptdel);

		MItemdeptupd = new JMenuItem("수정");
		MItemdeptupd.addActionListener(this);
		menusel.add(MItemdeptupd);

		MItemdeptsear = new JMenuItem("검색");
		MItemdeptsear.addActionListener(this);
		menusel.add(MItemdeptsear);

		MItemdeptlist = new JMenuItem("리스트");
		MItemdeptlist.addActionListener(this);
		menusel.add(MItemdeptlist);

		mnNewMenu = new JMenu("Employee");
		menuBar.add(mnNewMenu);
//////////////////////employee
		MItemempadd = new JMenuItem("추가");
		MItemempadd.addActionListener(this);
		mnNewMenu.add(MItemempadd);

		MItemempdel = new JMenuItem("삭제");
		MItemempdel.addActionListener(this);
		mnNewMenu.add(MItemempdel);

		MItemempupd = new JMenuItem("수정");
		MItemempupd.addActionListener(this);
		mnNewMenu.add(MItemempupd);

		MItemempsear = new JMenuItem("검색");
		MItemempsear.addActionListener(this);
		mnNewMenu.add(MItemempsear);

		MItememplist = new JMenuItem("리스트");
		mnNewMenu.add(MItememplist);
		MItememplist.addActionListener(this);

		mnNewMenu2 = new JMenu("CodeTitle");
		menuBar.add(mnNewMenu2);
////////////code_title
		MItemcodeadd = new JMenuItem("추가");
		MItemcodeadd.addActionListener(this);
		mnNewMenu2.add(MItemcodeadd);

		MItemcodedel = new JMenuItem("삭제");
		MItemcodedel.addActionListener(this);
		mnNewMenu2.add(MItemcodedel);

		MItemcodeupd = new JMenuItem("수정");
		MItemcodeupd.addActionListener(this);
		mnNewMenu2.add(MItemcodeupd);

		MItemcodesear = new JMenuItem("검색");
		MItemcodesear.addActionListener(this);
		mnNewMenu2.add(MItemcodesear);

		MItemcodelist = new JMenuItem("리스트");
		MItemcodelist.addActionListener(this);
		mnNewMenu2.add(MItemcodelist);

		getContentPane().setLayout(
				new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

	}

	@Override
	public void actionPerformed(ActionEvent e) {
        /////////////////////////////////employee
		if (e.getSource() == MItemempadd) {
			getContentPane().removeAll();
			actionPerformedMItemempadd(e);
		} else if (e.getSource() == MItemempdel) {
			getContentPane().removeAll();
			actionPerformedMItemempdel(e);
		} else if (e.getSource() == MItemempupd) {
			getContentPane().removeAll();
			actionPerformedMItemempupd(e);
		} else if (e.getSource() == MItemempsear) {
			getContentPane().removeAll();
			actionPerformedMItemempsear(e);
		} else if (e.getSource() == MItememplist) {
			getContentPane().removeAll();
			actionPerformedMItememplist(e);
			///////////////////////////////// department
		} else if (e.getSource() == MItemdeptadd) {
			getContentPane().removeAll();
			actionPerformedMItemdeptadd(e);
		} else if (e.getSource() == MItemdeptdel) {
			getContentPane().removeAll();
			actionPerformedMItemdeptdel(e);
		} else if (e.getSource() == MItemdeptupd) {
			getContentPane().removeAll();
			actionPerformedMItemdeptupd(e);
		} else if (e.getSource() == MItemdeptsear) {
			getContentPane().removeAll();
			actionPerformedMItemdeptsear(e);
		} else if (e.getSource() == MItemdeptlist) {
			getContentPane().removeAll();
			actionPerformedMItemdeptlist(e);
			///////////////////////////////////////codetitle
		} else if (e.getSource() == MItemcodeadd) {
			getContentPane().removeAll();
			actionPerformedMItemcodeadd(e);
		} else if (e.getSource() == MItemcodedel) {
			getContentPane().removeAll();
			actionPerformedMItemcodedel(e);
		} else if (e.getSource() == MItemcodeupd) {
			getContentPane().removeAll();
			actionPerformedMItemcodeupd(e);
		} else if (e.getSource() == MItemcodesear) {
			getContentPane().removeAll();
			actionPerformedMItemcodesear(e);
		} else {
			getContentPane().removeAll();
			actionPerformedMItemcodelist(e);
		}

	}
////////////////empolyee
	public void actionPerformedMItemempadd(ActionEvent e) {
		PanelEmployeeUI panel = new PanelEmployeeUI();
		panel.setDao(dao2);
		PanelEmployeeUI.ebtnadd.setText("추가");
		removeemp(panel);
	}

	public void actionPerformedMItemempdel(ActionEvent e) {
		PanelEmployeeUI panel = new PanelEmployeeUI();
		panel.setDao(dao2);
		PanelEmployeeUI.ebtnadd.setText("삭제");
		removeemp(panel);
	}

	public void actionPerformedMItemempsear(ActionEvent e) {
		PanelEmployeeUI panel = new PanelEmployeeUI();
		panel.setDao(dao2);
		PanelEmployeeUI.ebtnadd.setText("검색");
		removeemp(panel);
	}

	public void actionPerformedMItemempupd(ActionEvent e) {
		PanelEmployeeUI panel = new PanelEmployeeUI();
		panel.setDao(dao2);
		PanelEmployeeUI.ebtnadd.setText("수정");
		removeemp(panel);
	}

	public void actionPerformedMItememplist(ActionEvent e) {
		PanelEmployeeUI2 panel1 = new PanelEmployeeUI2();
		panel1.setDao(dao2);
		getContentPane().removeAll();
		getContentPane().add(panel1);
		getContentPane().revalidate();
	}
/////////////////////////////////department
	public void actionPerformedMItemdeptadd(ActionEvent e) {
		PanelDepartmentUI panel = new PanelDepartmentUI();
		panel.setDao(dao);
		PanelDepartmentUI.btnadd.setText("추가");
		removedept(panel);
	}

	public void actionPerformedMItemdeptdel(ActionEvent e) {
		PanelDepartmentUI panel = new PanelDepartmentUI();
		panel.setDao(dao);
		PanelDepartmentUI.btnadd.setText("삭제");
		removedept(panel);
	}

	public void actionPerformedMItemdeptupd(ActionEvent e) {
		PanelDepartmentUI panel = new PanelDepartmentUI();
		panel.setDao(dao);
		PanelDepartmentUI.btnadd.setText("수정");
		removedept(panel);
	}

	public void actionPerformedMItemdeptsear(ActionEvent e) {
		PanelDepartmentUI panel = new PanelDepartmentUI();
		panel.setDao(dao);
		PanelDepartmentUI.btnadd.setText("검색");
		removedept(panel);
	}

	public void actionPerformedMItemdeptlist(ActionEvent e) {
		PanelDepartmentUI2 panel = new PanelDepartmentUI2();
		panel.setDao(dao);
		getContentPane().removeAll();
		getContentPane().add(panel);
		getContentPane().revalidate();
	}
	/////////////////////////////////////codetitle
	public void actionPerformedMItemcodeadd(ActionEvent e) {
		PanelCodeTitleUI panel = new PanelCodeTitleUI();
		panel.setDao(dao3);
		PanelCodeTitleUI.btnadd1.setText("추가");
		removecodtitle(panel);
	}
	public void actionPerformedMItemcodedel(ActionEvent e) {
		PanelCodeTitleUI panel = new PanelCodeTitleUI();
		panel.setDao(dao3);
		PanelCodeTitleUI.btnadd1.setText("삭제");
		removecodtitle(panel);
	}
	public void actionPerformedMItemcodeupd(ActionEvent e) {
		PanelCodeTitleUI panel = new PanelCodeTitleUI();
		panel.setDao(dao3);
		PanelCodeTitleUI.btnadd1.setText("수정");
		removecodtitle(panel);
	}
	public void actionPerformedMItemcodesear(ActionEvent e) {
		PanelCodeTitleUI panel = new PanelCodeTitleUI();
		panel.setDao(dao3);
		PanelCodeTitleUI.btnadd1.setText("검색");
		removecodtitle(panel);

	}

	public void actionPerformedMItemcodelist(ActionEvent e) {
		PanelCodeTitleUI2 panel = new PanelCodeTitleUI2();
		panel.setDao(dao3);
		getContentPane().removeAll();
		getContentPane().add(panel);
		getContentPane().revalidate();
	}

	///////////////codetitle 
	public void removecodtitle(PanelCodeTitleUI panel){
		getContentPane().removeAll();
		getContentPane().add(panel);
		getContentPane().revalidate();
	}
	////////////////employee
	public void removeemp(PanelEmployeeUI panel){
		getContentPane().removeAll();
		getContentPane().add(panel);
		getContentPane().revalidate();
	}
	///////////////department
	public void removedept(PanelDepartmentUI panel){
		getContentPane().removeAll();
		getContentPane().add(panel);
		getContentPane().revalidate();
	}
	
}
